//
//  SecondaViewController.m
//  Four_years
//
//  Created by 中软国际019 on 15/11/9.
//  Copyright © 2015年 中软三班四年小组. All rights reserved.
//

#import "SecondaViewController.h"
#import "MyaTableViewCell.h"
#import "xinXi.h"
#import "ThirdaConViewController.h"
#import "ValueSender.h"

@interface SecondaViewController ()
{
    xinXi *x1;
    xinXi *x2;
    xinXi *x3;
    xinXi *x4;
    xinXi *x5;
}
@property    NSString *name;
@property    NSString *sex;
@property    NSString *birthday;
@property    NSString *school;
@property    NSString *special;
@end

@implementation SecondaViewController{
    UITableView *_tableView;
    NSMutableArray *tableViewArray;
    
}

-(id)init{
    if (self=[super init]) {
        self.navigationItem.title=@"我的信息";
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStyleGrouped];
    _tableView.dataSource=self;
    _tableView.delegate=self;
    [self.view addSubview:_tableView];
    [self initData];
    
    //修改按钮
    UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(WIDTH/2-50, HEIGHT/2+50, 100, 30)];
    button.backgroundColor=[UIColor colorWithRed:62/255.0 green:193/255.0 blue:209/255.0 alpha:1];
    
    [button setTitle:@"修改" forState:UIControlStateNormal];
    [_tableView addSubview:button];
    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
}
//修改事件
-(void)click:(UIButton *)button{
    NSLog(@"click");
    ThirdaConViewController *thirdaCtr=[[ThirdaConViewController alloc]init];
    [self.navigationController pushViewController:thirdaCtr animated:YES];
    
}


//初始化数据
-(void)initData{
    x1=[[xinXi alloc]initWithBiaoTi:@"昵称" andNeiRong:@""];
    x2=[[xinXi alloc]initWithBiaoTi:@"性别" andNeiRong:@""];
    x3=[[xinXi alloc]initWithBiaoTi:@"出生日期" andNeiRong:@""];
    x4=[[xinXi alloc]initWithBiaoTi:@"学校" andNeiRong:@""];
    x5=[[xinXi alloc]initWithBiaoTi:@"专业" andNeiRong:@""];
    NSArray *arr=@[x1,x2,x3,x4,x5];
    tableViewArray=[NSMutableArray arrayWithObjects:arr, nil];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return tableViewArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *group=tableViewArray[section];
    return group.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *name=@"cell";
    MyaTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:name];
    if (cell==nil) {
        cell=[[MyaTableViewCell alloc]init];
    }
    NSArray *group=tableViewArray[indexPath.section];
    xinXi *x=group[indexPath.row];
    cell.label.text=x.biaoTi;
    cell.label1.text=x.neiRong;
    cell.accessoryType=UITableViewCellAccessoryNone;
    return cell;

}

-(void)viewWillAppear:(BOOL)animated{//视图将要出现时走
    //获取单例对象
    ValueSender *valueSender=[ValueSender getInstance];
    x1.neiRong=valueSender.name;
    x2.neiRong=valueSender.sex;
    x3.neiRong=valueSender.birthday;
    x4.neiRong=valueSender.school;
    x5.neiRong=valueSender.speciality;
    [_tableView reloadData];//表视图 重新装载数据
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
